package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.domain.OfComment;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.service.IOfCommentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private ICommentService commentService;
    @Autowired
    private IOfCommentService iOfCommentService;

    //根据评论的ID和用户ID 获取用户对评论的子评论
    @GetMapping("/{commentId}/ofComments")
    @ResponseBody
    public Object getOfCommentsListByUserId(@PathVariable Long commentId){
        List<OfComment> list = iOfCommentService.getOfCommentsListByUserId(commentId);
        return list;
    }

    //获取每条评论的点赞次数
    @GetMapping("/{commentId}/likeNums")
    @ResponseBody
    public Object getCommentLikeNums(@PathVariable Long commentId){
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("likeNums", commentService.getCommentLikeNums(commentId));
        return map;
    }

    //通过评论ID获取指定的父评论
    @GetMapping("/{id}")
    @ResponseBody
    public Object get(@PathVariable Long id){
        Comment comment = commentService.get(id);
        return comment;
    }




    @PostMapping
    @ResponseBody
    public Object saveComment(Comment comment){
        return null;
    }



}
